package Logic;

import FrameWork.Event.TriggerManager;
import FrameWork.Model.Player;
import FrameWork.World.GodManager;
import Logic.EbSample.AuthService;
import Logic.EventSample.Order.OrderTrigger;
import Logic.EventSample.Scene.SceneService;
import Logic.Guild.Guild;
import Logic.Guild.GuildManager;
import Logic.SceneSample.SimpleScene;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Test {

    public static Logger logger = Logger.getLogger(Test.class);

    public static void main(String[] args) throws InterruptedException {
        testFuture();
        //ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        //testJoinGuild(context);
    }

    public static void testJoinGuild(ApplicationContext context) throws InterruptedException {
        Guild guild = new Guild();
        guild.setId(2018522);
        guild.setMenberLimit(10);
        guild.setJoinGold(50);
        GuildManager manager = context.getBean(GuildManager.class);
        manager.addGuild(guild);
        String name = "mike";
        for (int i=0;i<20;i++){
            Player player = new Player(name+i);
            player.setGold(100);
            manager.joinGuild(player,guild.getId());
        }
        Thread.sleep(10);
        for (int i=20;i<30;i++){
            Player player = new Player(name+i);
            player.setGold(100);
            manager.joinGuild(player,guild.getId());
        }
    }

    public static void testEb(ApplicationContext context){
        AuthService service = context.getBean(AuthService.class);
        for (int i=0;i<20;i++){
            service.onLogic();
        }
    }

    public static void testFuture(){
        CompletableFuture<String> future = new CompletableFuture<>();
        ExecutorService service = Executors.newSingleThreadExecutor();

        service.execute(()->{
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            future.complete(Thread.currentThread().getName());
        });
        future.thenAccept(threadName->{
            System.out.println("执行线程："+threadName);
            System.out.println("回调线程: "+Thread.currentThread().getName());
        });
        for (int i=0;i<1000;i++){
            System.out.println(i);
        }
    }

    public static void testService(ApplicationContext context){
        SceneService sceneService = context.getBean(SceneService.class);
        //sceneService.enterScene(new Player(),0,1);
    }

    public static void testFightEvent(){
        //TriggerManager.getTrigger(KillMonsterTrigger.class).fire(new Player());
    }

    public static void testOrderTrigger(ApplicationContext context){
        TriggerManager.getTrigger(OrderTrigger.class).fire();
    }

    public static void upGradeGuild(){
        //Player player = new Player();
       // TriggerManager.getTrigger(GuildTrigger.class).fire(player,GuildEventType.UPGRADE);
    }

    //测试部署场景
    public static void testScene(GodManager manager){
        for (int i=0;i<10;i++){
            manager.deployScene(new SimpleScene());
        }
    }


}
